package com.atguigu.blog.app;

import com.atguigu.blog.dto.response.Result;
import com.atguigu.blog.pojo.Video;
import com.atguigu.blog.pojo.VideoInfo;
import com.atguigu.blog.service.VideoInfoService;
import com.atguigu.blog.service.VideoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO 小程序用 待开发
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/vod")
public class VodAppController {

    @Autowired
    private VideoInfoService videoInfoService;

    @Autowired
    private VideoService videoService;

    /**
     * 查询视频列表
     */
    @GetMapping("/gets")
    public Result vodList(String query) {
        QueryWrapper<VideoInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("video_name");
        queryWrapper.eq("status", 1);// 查询审核已通过的视频
        if (StringUtils.isNotBlank(query)) {
            queryWrapper.like("video_name", query);
        }
        List<VideoInfo> videoInfoList = videoInfoService.list(queryWrapper);
        return Result.ok(videoInfoList);
    }

}
